package state;

/**
 * @author mubei
 * @date 2021/11/20
 * @description  测试礼让线程
 */
public class TestYield {

    public static void main(String[] args) {
        MyYield myYield = new MyYield();


        Thread a = new Thread(myYield, "A");
        Thread b = new Thread(myYield, "B");

        a.start();
        b.start();

    }


}

class  MyYield implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        Thread.yield();
        System.out.println(Thread.currentThread().getName()+"线程停止执行");
    }
}
